package com.smartlifev30.mvp.presenter;

import com.smartlifev30.mvp.module.IModule;
import com.smartlifev30.mvp.view.IView;

import java.lang.ref.WeakReference;

/**
 * @author tys
 * @date 2018/8/14
 */

public class BasePresenter<V extends IView, M extends IModule> {

    protected WeakReference<V> view;
    protected M model;

    public BasePresenter(V view) {
        this(view, null);
    }

    public BasePresenter(V view, M model) {
        this.view = new WeakReference<>(view);
        this.model = model;
    }

    public void detach() {
        view.clear();
    }

    public void toast(String context) {
        V v;
        if ((v = view.get()) != null) {
            v.toast(context);
        }
    }


    public void showLoading() {
        V v;
        if ((v = view.get()) != null) {
            v.showLoading();
        }
    }


    public void dismissLoading() {
        V v;
        if ((v = view.get()) != null) {
            v.dismissLoading();
        }
    }


}